package com.fit.spring.boot.properties.autoscan.autoconfigure;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;



/**
 * 自动扫描配置文件
 * @author hcl
 */
public class AutoScanPropertiesProperties {
	
	private static Logger log = LoggerFactory.getLogger(AutoScanPropertiesProperties.class);

	//查找的范围
	private static String prefix = "classpath*:**/*-";

	//默认的模式
	private static String mustActive = "auto";

	//文件后缀集合
	private static String[] suffixs = {".properties",".yml",".yaml"};

    //优先的模式
	public static String priorityActiveKey = "spring.profiles.priority-active";

	/**
	 * @describe: 获取auto uri
	 * @author: hcl  
	 * @date: 2018/7/19 18:13
	 * @param: []  
	 * @return java.lang.String  
	 */
	public static String getUriByAutoActive(){
	    return getUriByActive(mustActive);
    }


	/**
	 * @describe: 根据激活的模式获取需要被扫描的文件路径
	 * @author: hcl  
	 * @date: 2018/7/19 17:42
	 * @param: [active]  
	 * @return java.lang.String  
	 */
	public static String getUriByActive(String active){
		StringBuilder uri = new StringBuilder();
		for(int i=0; i<suffixs.length; i++){
			String suffix = suffixs[i];
			String u = prefix + active + suffix;
			if(i == 0){
				uri.append(u);
			}else{
				uri.append(","+u);
			}
		}
		return uri.toString();
	}


	/**
	 * @describe: 根据激活的模式获取所有的uri
	 * @author: hcl  
	 * @date: 2018/7/19 17:49
	 * @param: [active]  
	 * @return java.util.List<java.lang.String>  
	 */
	public static List<String> getAllUri(String[] actives){
		List<String> list = new ArrayList<>();
		for(String active : actives){
			list.add(getUriByActive(active));
		}
		return list;
	}
}
